package com.common.www.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Random;

@Controller
public class GlobalController {
    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login() {
        return "/login/login.html";
    }

    static int oneDayPrice = 1000;
    static int twoDayPrice = 1000;//两天一换
    static int rentPrice = 4000;//房租
    static int otherPrice = 1500;//水电气物管费
    static int initPrice = 100000;//初始投资

    static int endCount = 180;//收支平衡的日期

    public static void main(String[] args) {
        float income = (oneDayPrice + (twoDayPrice / 2) * 1f) / endCount;//平均单天的收入增长率

        int calDay = 1;
        float totalIncome = 0;//总收入
        float totalOutcome = initPrice;//总支出
        float totalLiRun = 0;//总利润

        for (int i = 0; i < 1825; i++) {
            Random random = new Random();//默认构造方法
            int r = random.nextInt(10);
            float rate = r / 100f;//每天随机收入增长值
            float fixIncome = calDay * income;//固定收入
            float dayIncome = 0;//单天收入按照波动性来计算
            if (calDay % 2 == 0) {//偶数时正向增长收入
                dayIncome = fixIncome + fixIncome * rate;
            } else {//奇数负向增长收入
                dayIncome = fixIncome - fixIncome * rate;
            }

            float dayOutCome = 0;
            //当发现固定支出大于收入后认为干预减小进货量
            dayOutCome = dayIncome * 1.05f;

            if (dayOutCome > oneDayPrice + (twoDayPrice / 2f)) {
                dayOutCome = oneDayPrice + (twoDayPrice / 2f);
            }
            //保证最小每天进货500元的菜品
            if (dayOutCome < 500) {
                dayOutCome = 500;
            }
            if (dayIncome / dayOutCome * 1f > 2f) {
                dayIncome = dayOutCome * 2f;
            }
            if (calDay % 30 == 0) {//每个月的额外开销
                System.out.println("每个月的额外开销");
                dayOutCome += rentPrice + otherPrice;
            }

            totalIncome += dayIncome;
            totalOutcome += dayOutCome;


            float liRun = dayIncome - dayOutCome;//当天利润
            totalLiRun += liRun;
            System.out.println("第" + calDay + "天" + "  收入:" + dayIncome + " 支出：" + dayOutCome + " 总利润：" + totalLiRun);
            calDay++;
        }
        System.out.println("总天数 " + calDay + " 总收入：" + totalIncome + " 总支出:" + totalOutcome);


    }
}
